package com.zhangchuchu.neohealth.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhangchuchu.neohealth.entity.Community;
import com.zhangchuchu.neohealth.entity.DTO.CommunityDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * (Community)表数据库访问层
 *
 * @author makejava
 * @since 2025-03-29 20:22:53
 */
@Mapper
public interface CommunityMapper extends BaseMapper<Community> {

    @Select("SELECT c.id, c.title, c.content, c.image, c.region, c.created_at, c.likes," +
            "u.nickname, u.avatar, co.content AS comment_content, co.created_at AS comment_created_at " +
            "FROM community c " +
            "LEFT JOIN users u ON c.user_id = u.id " +
            "LEFT JOIN comments co ON c.comment_id = co.id " +
            "WHERE c.comment_id = #{commentId} AND c.user_id = #{userId}")
    List<CommunityDTO> getCommunityWithUserAndComment(@Param("commentId") Long commentId,
                                                      @Param("userId") Long userId);
    @Select("SELECT c.id, c.title, c.content, c.image, c.region, c.created_at, c.likes," +
            "u.nickname, u.avatar " +
            "FROM community c " +
            "LEFT JOIN users u ON c.user_id = u.id ")
    List<CommunityDTO> getCommunity();
}
